﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Zyg.SSO.Core.Business;

namespace Zyg.SSO.Web.Admin.Role
{
    public partial class AddRole : Zyg.SSO.Web.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!base.Account.HavePermission(Permission.RoleManage))
                {
                    throw new Exception("你无权查看此页面");
                }
            }
        }

        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            Zyg.SSO.Core.Business.Role role = new Zyg.SSO.Core.Business.Role();

            role.Id = Guid.NewGuid();
            role.Name = RoleName.Text;
            role.Remark = RoleRemark.Text;

            role.Save();

            Zyg.SSO.Core.Business.Log log = new Zyg.SSO.Core.Business.Log();
            log.AccountId = base.Account.Id;
            log.ModuleId = Zyg.SSO.Core.Business.Module.Role.Id;
            log.Message = string.Format("管理员 {0} 添加了角色 {1}", base.Account.Email, role.Name);

            log.Save();

            WriteBackScript("alert('添加角色成功')");
        }
    }
}
